package com.ermao.mymes.handler.service.deduplication;

import cn.hutool.core.util.StrUtil;
import com.ermao.mymes.common.domain.TaskInfo;
import com.ermao.mymes.common.enums.DeduplicationType;
import org.springframework.stereotype.Service;

/**
 * @author Ermao
 * Date: 2022/5/9 14:44
 */
@Service
public class FrequencyDeduplicationService extends AbstractDeduplicationService {

	public FrequencyDeduplicationService() {
		deduplicationType = DeduplicationType.FREQUENCY.getCode();
	}

	private static final String PREFIX = "FRE";

	/**
	 * 业务规则去重 构建key
	 * <p>
	 * key ： receiver + templateId + sendChannel
	 * <p>
	 * 一天内一个用户只能收到某个渠道的消息 N 次
	 *
	 * @param taskInfo
	 * @param receiver
	 * @return
	 */
	@Override
	public String deduplicationSingleKey(TaskInfo taskInfo, String receiver) {
		return PREFIX + StrUtil.C_UNDERLINE
				+ receiver  + StrUtil.C_UNDERLINE
				+ taskInfo.getMessageTemplateId() + StrUtil.C_UNDERLINE
				+ taskInfo.getSendChannel();
	}
}
